package com.betterjr.modules.application;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.web.ControllerExceptionHandler;
import com.betterjr.common.web.ControllerExceptionHandler.ExceptionHandler;
import com.betterjr.common.web.Servlets;

@Controller
@RequestMapping(value = "/Platform/ApplicationGroup")
public class ApplicationGroupController {

    private static final Logger logger = LoggerFactory.getLogger(ApplicationGroupController.class);

    @Reference(interfaceClass = IApplicationGroupService.class)
    private IApplicationGroupService applicationGroupService;

    /**
     * 
     * @Title: findApplicationGroupDetail 
     * @Description: 查询分组详细信息 
     * @param request
     * @param groupId 主键id
     * @param count 是否查询应用数量 1 查询     2 不查询
     * @param applicationList   是否查询应用集合  1 查询  2 不查询
     * @param anBusinStatus   应用机构的状态状态 1未生效 2已生效 9已失效
     * @return 查询分组详细信息
     * @throws 
     * @author xuyp
     * @date 2017年11月15日 下午5:08:47
     */
    @RequestMapping(value = "/findApplicationGroupDetail", method = RequestMethod.POST)
    public @ResponseBody String findApplicationGroupDetail(final HttpServletRequest request, Long groupId, String count,
            String applicationList, String businStatus) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationGroupService.webFindApplicationGroupDetail(groupId, count, applicationList,
                        businStatus);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: queryApplicationGroupList 
     * @Description: 查询单条分组应用的详细信息
     * @param anGroupId 主键id
     * @param count 是否查询应用数量 1 查询     2 不查询
     * @param applicationList   是否查询应用集合  1 查询  2 不查询
     * @param anBusinStatus   状态应用中间表中的状态状态 1未生效 2已生效 9已失效
     * @return 查询单条分组应用的详细信息
     * @throws 
     * @author xuyp
     * @date 2017年11月15日 下午5:10:24
     */
    @RequestMapping(value = "/queryApplicationGroupList", method = RequestMethod.POST)
    public @ResponseBody String queryApplicationGroupList(final HttpServletRequest request, String count,
            String applicationList, String businStatus) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationGroupService.webQueryApplicationGroupList(count, applicationList, businStatus);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: saveOrUpdateApplicationGroup 
     * @Description: 新增或者修改应用分组  
     * @param request
     * @return 新增或者修改应用分组  
     * @throws 
     * @author xuyp
     * @date 2017年11月15日 下午5:11:40
     * ID  
     * applicationGroupName
     * 
     */
    @RequestMapping(value = "/saveOrUpdateApplicationGroup", method = RequestMethod.POST)
    public @ResponseBody String saveOrUpdateApplicationGroup(final HttpServletRequest request) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationGroupService.webSaveOrUpdateApplicationGroup(anMap);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: saveDeleteApplicationGroup 
     * @Description: 删除应用分组 
     * @param request
     * @param id
     * @return  删除应用分组
     * @throws 
     * @author xuyp
     * @date 2017年12月5日 下午4:43:46
     */
    @RequestMapping(value = "/saveDeleteApplicationGroup", method = RequestMethod.POST)
    public @ResponseBody String saveDeleteApplicationGroup(final HttpServletRequest request, Long id) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationGroupService.webSaveDeleteApplicationGroup(id);
            }
        }, "操作失败", logger);
    }

}
